﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using Maticsoft.Common;
using LTP.Accounts.Bus;
namespace NCEdu.Web.leave
{
    public partial class Modify : Page
    {       

        		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				if (Request.Params["id"] != null && Request.Params["id"].Trim() != "")
				{
					int leaveId=(Convert.ToInt32(Request.Params["id"]));
					ShowInfo(leaveId);
				}
			}
		}
			
	private void ShowInfo(int leaveId)
	{
		NCEdu.BLL.leave bll=new NCEdu.BLL.leave();
		NCEdu.Model.leave model=bll.GetModel(leaveId);
		this.lblleaveId.Text=model.leaveId.ToString();
		this.txtstuNo.Text=model.stuNo.ToString();
		this.txttel.Text=model.tel;
		this.txtstuTitle.Text=model.stuTitle;
		this.txtleaveReason.Text=model.leaveReason;
		this.txt请假日期.Text=model.请假日期.ToString();
		this.txt截至日期.Text=model.截至日期.ToString();
		this.txt请假类型.Text=model.请假类型;

	}

		public void btnSave_Click(object sender, EventArgs e)
		{
			
			string strErr="";
			if(!PageValidate.IsNumber(txtstuNo.Text))
			{
				strErr+="stuNo格式错误！\\n";	
			}
			if(this.txttel.Text.Trim().Length==0)
			{
				strErr+="tel不能为空！\\n";	
			}
			if(this.txtstuTitle.Text.Trim().Length==0)
			{
				strErr+="stuTitle不能为空！\\n";	
			}
			if(this.txtleaveReason.Text.Trim().Length==0)
			{
				strErr+="leaveReason不能为空！\\n";	
			}
			if(!PageValidate.IsDateTime(txt请假日期.Text))
			{
				strErr+="请假日期格式错误！\\n";	
			}
			if(!PageValidate.IsDateTime(txt截至日期.Text))
			{
				strErr+="截至日期格式错误！\\n";	
			}
			if(this.txt请假类型.Text.Trim().Length==0)
			{
				strErr+="请假类型不能为空！\\n";	
			}

			if(strErr!="")
			{
				MessageBox.Show(this,strErr);
				return;
			}
			int leaveId=int.Parse(this.lblleaveId.Text);
			int stuNo=int.Parse(this.txtstuNo.Text);
			string tel=this.txttel.Text;
			string stuTitle=this.txtstuTitle.Text;
			string leaveReason=this.txtleaveReason.Text;
			DateTime 请假日期=DateTime.Parse(this.txt请假日期.Text);
			DateTime 截至日期=DateTime.Parse(this.txt截至日期.Text);
			string 请假类型=this.txt请假类型.Text;


			NCEdu.Model.leave model=new NCEdu.Model.leave();
			model.leaveId=leaveId;
			model.stuNo=stuNo;
			model.tel=tel;
			model.stuTitle=stuTitle;
			model.leaveReason=leaveReason;
			model.请假日期=请假日期;
			model.截至日期=截至日期;
			model.请假类型=请假类型;

			NCEdu.BLL.leave bll=new NCEdu.BLL.leave();
			bll.Update(model);
			Maticsoft.Common.MessageBox.ShowAndRedirect(this,"保存成功！","list.aspx");

		}


        public void btnCancle_Click(object sender, EventArgs e)
        {
            Response.Redirect("list.aspx");
        }
    }
}
